package com.ybkj.daijia.common;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * <pre>Result Json API</pre>
 * <small> 2019-12-03 | xwy </small>
 */
@Data
@AllArgsConstructor
public class Res<T> {
    private Integer code;
    private String msg;
    private T data;
    private Res(){}
    private Res(T data){
        this.code= CodeMsg.SUCCESS.getCode();
        this.msg= CodeMsg.SUCCESS.getMsg();
        this.data=data;
    }
    public static <T> Res<T> ok(){
        return new Res<>(null);
    }
    public static <T> Res<T> ok(T data){
        return new Res<>(data);
    }

    public static <T> Res<T> build(CodeMsg cm){
        return new Res<>(cm.getCode(),cm.getMsg(),null);
    }
    public static <T> Res<T> build(CodeMsg cm, T data){
        return new Res<>(cm.getCode(),cm.getMsg(),data);
    }

    public static <T> Res<T> fail(){
        return new Res<>(CodeMsg.Fail.getCode(), CodeMsg.Fail.getMsg(),null);
    }
    public static <T> Res<T> fail(T data){
        return new Res<>(CodeMsg.Fail.getCode(), CodeMsg.Fail.getMsg(),data);
    }
}
